package org.user.controller;


import io.seata.core.context.RootContext;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.user.bean.UserBean;
import org.user.dynamicFeignClient.DynamicFeignClient;
import org.user.orderfallback.OrderServiceApiFegin;
import org.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;


@RestController
//@Import(FeignClientsConfiguration.class)
public class UserController {
  //  Feign.Builder builder;

//    //创建构造器
//    public UserController(Decoder decoder, Encoder encoder, Client client, Contract contract) {
//        this.builder = Feign.builder()
//                .client(
//                        client
//                )
//                .encoder(encoder)
//                .decoder(decoder)
//                .contract(contract).target();
//    }

    @Value("${userServerNAME}")
    private String userServerName;

    @Autowired
    UserService userService;

    @Autowired
    DynamicFeignClient<OrderServiceApiFegin> client;

    @Autowired
    OrderServiceApiFegin orderServiceApiFegin;


    @RequestMapping("/insertUser")
    public void insertUser() {
            UserBean userBean=new UserBean();
            userBean.setUserName(userServerName);
            userService.insertUser(userBean);

    }


    @RequestMapping("/insertUser2")
    public void insertUser2() {
        try {
            String xid = RootContext.getXID();
            String service_name="orderServer8082";
           OrderServiceApiFegin orderServiceApiFegin=client.GetFeignClient(OrderServiceApiFegin.class,
                   service_name);
            System.out.println(orderServiceApiFegin.insertOrder(xid));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
